package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.bean.Employee;
import com.qf.dao.EmployeeMapper;
import com.qf.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/**
 * 2019/11/19
 * Administrator
 * ssm1119
 * 面向对象面向君  不负代码不负卿
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public PageInfo<Employee> getall(int pageIndex,int pageSize,String username,String rolename,String deptname) {
        //1.指定分页参数
        PageHelper.startPage(pageIndex, pageSize);
        //2.调取dao层方法
        HashMap map = new HashMap();
        map.put("uname",username);
        map.put("rname",rolename);
        map.put("dname",deptname);
        List<Employee> employeeList = employeeMapper.findall(map);
        //3.封装pageInfo
        PageInfo info = new PageInfo(employeeList);
        return info;
    }

    @Override
    public Employee login(String username, String password) {
        Employee employee = employeeMapper.login(username);
        if (employee != null) {
            //用户名正确
            if(password.equals(employee.getLoginpassword())){
                    return employee;
            }
            return null;

        }
        return null;
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return 0;
    }

    @Override
    @Transactional
    public int insert(Employee record) {
        return employeeMapper.insert(record);
    }

    @Override
    public int insertSelective(Employee record) {
        return 0;
    }

    @Override
    public Employee selectByPrimaryKey(Integer id) {
        return employeeMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional
    public int updateByPrimaryKeySelective(Employee record) {
        return employeeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    @Transactional
    public int updateByPrimaryKey(Employee record) {
        return employeeMapper.updateByPrimaryKey(record);
    }
}
